<template>
  <div id="app" class="text-gray-800">
    <router-view />
  </div>
</template>

<script>
export default {
  mounted() {
    const handler = res => {
      const user = this.$store.state.user
      if (!user) {
        return
      }
      if (res.id === user.id) {
        this.$store.commit('clearUser')
        this.$router.push('/login')
        this.$toast('已禁用，如有疑问请与代理联系！')
      }
    }

    this.$channel.bind('kickout', handler)

    this.$once('hook:beforeDestroy', () => {
      this.$channel.unbind('kickout', handler)
    })
  },
  watch: {
    '$route.path': function(val, old) {
      if (old === '/login' || val === '/login') {
        return
      }
      this.axios.get('/info/update').then(res => {
        const { user, sys } = res.data.data
        this.$store.commit('setUser', user)
        this.$store.commit('setSys', sys)
      })
    },
  },
}
</script>
<style>
@import url(//at.alicdn.com/t/font_2907849_tjp00wil7v.css);
</style>
